package cn.schoolwow.ams.test.module.api.aware;

import cn.schoolwow.ams.domain.block.common.operation.FormBlockHandlerBlockOperation;
import cn.schoolwow.ams.domain.block.form.FormBlockConfigAware;
import cn.schoolwow.ams.domain.block.form.FormBlockOperationHandler;
import cn.schoolwow.ams.domain.block.form.FormBlockOption;
import cn.schoolwow.ams.domain.block.form.FormBlockRequest;
import cn.schoolwow.ams.test.module.api.domain.ExecuteRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

@Service
public class ExecuteAPIAware extends FormBlockConfigAware {
    @Override
    public FormBlockOption getAMSBlockConfig() {
        FormBlockOption formBlockOption = new FormBlockOption("test", "执行请求", ExecuteRequest.class);
        {
            FormBlockHandlerBlockOperation formBlockHandlerBlockOperation = new FormBlockHandlerBlockOperation("执行请求", new FormBlockOperationHandler() {
                @Override
                public JSONObject handle(FormBlockRequest formBlockRequest) throws Exception {
                    System.out.println("收到请求!"+ JSON.toJSONString(formBlockRequest));
                    JSONObject result = new JSONObject();
                    result.put("statusCode", "200");
                    result.put("responseHeader", "无");
                    result.put("responseBody", "无");
                    return result;
                }
            });
            formBlockOption.formBlockHandlerBlockOperationList.add(formBlockHandlerBlockOperation);
        }
        return formBlockOption;
    }
}
